package edu.nf.supermarket.config;

import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.ServletRegistration;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * @author yjj
 * @date 2025-05-19
 */
public class WebInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[0];
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{RootConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        //限制每次上传的文件大小为2MB，限制本次请求的所有文件最大大小为5MB,当达到100kb时写入文件
        MultipartConfigElement multipartConfigElement
                =new MultipartConfigElement("",5*1024*1024,50*1024*1024,100*1024);
        registration.setMultipartConfig(multipartConfigElement);
        registration.setLoadOnStartup(0);
    }



}
